package com.macro.mall.commission.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.macro.mall.commission.entity.OrderPredicateEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

/**
 * 订单佣金预估 mapper
 *
 * @author xuyanjun
 * @date 2019-12-11
 */
public interface OrderPredicateMapper extends BaseMapper<OrderPredicateEntity> {

    /**
     * 根据订单id修改已结算状态
     *
     * @param orderId     id
     * @return 受影响的行数
     */
    @Update("update commission_order_settle set settled=1 where order_id=#{orderId}; ")
    int updateSettledByOrderId(@Param("orderId") long orderId);

    /**
     * 根据创建时间获取用户佣金总和
     *
     * @param userId    用户id
     * @param beginTime 开始时间
     * @param endTime   结束时间
     * @return 佣金总和
     */
    @Select(" select sum(amount) from commission_order_settle where user_id=#{userId} and create_time between #{beginTime} and #{endTime}; ")
    Long sumAmountByCreateTimeOfUser(@Param("userId") long userId, @Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime);
}

